//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;

namespace OpenLS.Spreadsheet.Functions
{
    static class FunctionHelper
    {
        public static List<double> GetOnlyDouble(object[] args)
        {
            if (args[0] is Range)
            {
                Range r = (Range)args[0];
                //\\check
                List<object> values = new List<object>();
                foreach (Cell c in r.GetNonEmptyCells())
                    values.Add(c.Value);
                return GetOnlyDouble(values);
            }
            List<double> result = new List<double>();
            foreach (object o in args)
            {
                if (o is double)
                    result.Add((double)o);
            }
            return result;
        }
        public static List<double> GetOnlyDouble(List<object> args)
        {
            List<double> result = new List<double>();
            foreach (object o in args)
            {
                if (o is double)
                    result.Add((double)o);
            }
            return result;
        }
        public static List<double> GetOnlyDoubleOrBoolean(object[] args) //\\check errors
        {
            List<double> result = new List<double>();
            foreach (object o in args)
            {
                if (o is double)
                    result.Add((double)o);
                if (o is bool)
                {
                    bool b = (bool)o;
                    if (b)
                        result.Add(1);
                    else
                        result.Add(0);
                }
            }
            return result;
        }
    }
}
